package com.itheima.app.manager.omsManager;

import com.itheima.autoconfig.oss.OssTemplate;
import com.itheima.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 图片上传
 */
@Component
public class OmsManager {
    @Autowired
    OssTemplate ossTemplate;

    /**
     * 图片上传
     *
     * @param photoFile
     * @return
     */
    public String photoUpload(MultipartFile photoFile) {
        String imagePath = null;
        try {
            //调用图片上传功能
            imagePath = ossTemplate.upload(photoFile.getOriginalFilename(), photoFile.getInputStream());
        } catch (IOException e) {
            throw new BusinessException("图片上传失败");
        }
        return imagePath;
    }
}
